home *** CD-ROM | disk | FTP | other *** search
- Path: news.eunet.ch!usenet
- From: Oliver Plohmann <opl@esec.ch>
- Newsgroups: comp.lang.c++
- Subject: Binary association problem
- Date: Tue, 20 Feb 1996 07:49:56 +0100
- Organization: ESEC SA
- Message-ID: <31296F14.88E@esec.ch>
- NNTP-Posting-Host: everest.esec.ch
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0b6a (X11; I; HP-UX A.09.05 9000/735)
-
- Hello,
-
- I habe two classes that reference each other. I put those classes into
- one header to get the code linked. Due to the nature of my application I
- have now several class associated with each eather in one header. My
- compiler can't handle it any more and creates a fatal error. I could
- switch compiler but every compiler has some problem. I think it would
- only mean substituting problems for other problems.
-
- To split up the code into separate headers I have changed associations
- between classes to be pointer references (otherwise I get cyclic
- inclusion of headers). Whith this approach the code compiles and links
- fine. Below some sample code to show this. Unhappily, I get a protection
- violation. The reason is probably a scoping issue. Does anybody know a
- way out of this?
-
- Thank you, Olli Plohmann
-
- -------------------------a.h------------------------
-
- class B;
-
- class A {
-
- int* x;
- public:
-
- A() {};
- ~A() {};
-
- void operator+(const int& i) {
- *x=i; // protection violation !
- };
- };
-
- -------------------------b.h------------------------
- #include "a.h"
-
- class A;
-
- class B {
-
- A* x;
- public:
-
- B() { *x=5; };
- ~B() {};
- };
-
- --------------------------test.cpp--------------------
-
- #include "b.h"
-
- void main()
- {
- B b; // protection violation in A::operator=(const int& i)
- }
-